home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / 173basm.zip / GIVEBK31.ASM < prev    next >
Assembly Source File  |  1988-04-26  |  14KB  |  272 lines

  1. page 88,132
  2. Comment ~
  3.              GIVEBACK (Version 3.1) Description and Source Code
  4.  
  5.         Kurt Riegel, 3019 North Oakland Street, Arlington, VA 22207
  6.         ASTRO Bulletin Board, data 202-524-1837, voice 703-522-5427
  7.  
  8.  
  9. (The description below is cast in terms of using GIVEBACK under DESQview or
  10. DoubleDos, in conjunction with the bulletin board program RBBS-PC, but the same
  11. procedure is usable from ANY calling program, for example using CALL GIVEBACK
  12. in compiled BASIC.)
  13.  
  14. This small assembly language routine follows information provided in the
  15. DESQview (DV) 2.01 manual, and in the DoubleDos (DD) 4.0 manual.
  16.  
  17. The idea is simple, but powerful.  DESQview kindly terminates processing in a
  18. window if the computer pauses for a standard dos keyboard function, saving the
  19. rest of the time slice for jobs in other windows.  But in other kinds of loops,
  20. for example the loop in RBBS bulletin board which watches for the telephone to
  21. ring, lots of time is wasted, uselessly looking for a phone ring every few
  22. milliseconds.  Once a second would be quite enough!
  23.  
  24. By calling this routine from the end of a wasteful loop in a program, DESQview
  25. will be forced to "give back" the rest of the time in that time slice, that is,
  26. you will execute the loop only once per time slice rather than many times.
  27. This greatly speeds up jobs in the other DV windows, without affecting the
  28. calling program at all.
  29.  
  30. The most wasteful RBBS task is waiting for the telephone to ring; another is
  31. waiting for the user to select a command and hit the Return key.  So we CALL
  32. this procedure at the end of these loops.  The table below summarizes actual
  33. measurements made with DV on an AST Premium 286 (10 MHz, zero wait state),
  34. relative to speed on the same machine without DV, running a single job.  DV
  35. SETUP default performance settings were 9 slices foreground, 3 slices
  36. background.  This improvement would be larger and MUCH more noticeable on a
  37. slower machine.
  38.  
  39. Similarly, DoubleDos normally allocates two thirds of the computing cycles to
  40. the Visible task, and the remaining third to the Invisible task (plenty for
  41. the RBBS bulletin board).  The loss of cycles is sometimes noticeable, and this
  42. reclaims them when not really needed by RBBS.  You can even use this to speed
  43. up both nodes of RBBS, when one is in the Visible section and the other is in
  44. the Invisible section (you would probably choose PRIORITY=EQUAL with 2 nodes).
  45. DD version 4.00 has a special interrupt that allows the programmer to "give
  46. back" up to 255 time slices of duration 55 milliseconds each.  This procedure
  47. gives back 6 slices, about a third of a second at the old 4.77 MHz clock rate.
  48.                         
  49. The table below summarizes actual speed measurements with and without
  50. GIVEBACK, running under both DoubleDos and DESQview.  The speedup is
  51. wonderful, about 65%.  Once you use it, you'll never go back.
  52.  
  53.                         
  54.         Non-bbs speed   │  Waiting for Ring  │  Caller On
  55.         ────────────────┼────────────────────┼──────────────────────
  56. DV:     Unmodified      │        74%         │    74%              
  57.         With GIVEBACK   │        98%         │ variable, average 86%   
  58.         ────────────────┼────────────────────┼──────────────────────
  59. DD:     Unmodified      │        57%         │    57%              
  60.         With GIVEBACK   │        94%         │ variable, average 80%   
  61.         ────────────────┴────────────────────┴──────────────────────
  62.  
  63. Challenge for multitasking RBBS enthusiasts:  There are additional wasteful
  64. loops in RBBS--put on your best Sherlock outfit, and go snooping for places to
  65. CALL GIVEBACK.  Please keep in touch with me on your progress through the
  66. telephone numbers or address posted at the top of this file.
  67.  
  68.  
  69.                            ┌─────────────────────┐                          
  70.                            │     RBBS 16.1       │
  71. ┌──────────────────────────┴─────────────────────┴─────────────────────────┐
  72. │   Starting with version 16.1, RBBS has the implementation for GIVEBACK   │
  73. │   already built in.  The original release version omitted one call,      │
  74. │   the one within the loop waiting for the telephone to ring.  It is      │
  75. │   repaired by making the small change below in RBBSSUB2.BAS              │
  76. │                                                                          │
  77. │  270 . . .                                                               │
  78. │      call giveback:WEND                                                  │
  79. │                                                                          │
  80. │    Then compile the modified RBBSSUB2.BAS, and LINK  RBBSSUB2.OBJ        │
  81. │    together with  GIVEBK31.OBJ and the rest of the normal RBBS  OBJect   │
  82. │    files package.                                                        │
  83. └──────────────────────────────────────────────────────────────────────────┘
  84.  
  85.  
  86.                                                                             
  87.                            ┌─────────────────────┐                          
  88.                            │    RBBS 15.1c       │                          
  89. ┌──────────────────────────┴─────────────────────┴─────────────────────────┐
  90. │    To implement GIVEBACK, modify RBBSSUB1.BAS by the addition of the     │
  91. │    lower case letter portion) in 2 lines only:                           │
  92. │                                                                          │
  93. │  270 IF RECYCLE.WAIT > 0 THEN _                              ' CPC15-1C  │
  94. │      IF TI! > INACTIVE.DELAY! THEN _                         ' CPC15-1C  │
  95. │      SUBROUTINE.PARAMETER = 8 : _                            ' CPC15-1C  │
  96. │      EXIT SUB                                                ' CPC15-1C  │
  97. │      call giveback:WEND                                                  │
  98. │      . . .                                                               │
  99. │ 1526 Y$ = KEY.PRESSED$                                                   │
  100. │      IF Y$ <> "" THEN _                                                  │
  101. │      GOTO 1545                                                           │
  102. │      call giveback:GOTO 1525                                             │
  103. │                                                                          │
  104. │    Then compile the modified RBBSSUB1.BAS, and LINK  RBBSSUB1.OBJ        │
  105. │    together with  GIVEBK31.OBJ and the rest of the normal RBBS  OBJect   │
  106. │    files package.                                                        │
  107. └──────────────────────────────────────────────────────────────────────────┘
  108.  
  109.                            ┌─────────────────────┐                          
  110.                            │    RBBS 14.1d       │                          
  111. ┌──────────────────────────┴─────────────────────┴─────────────────────────┐
  112. │    To implement GIVEBACK, modify RBBS-SUB.BAS version 14.1D (by the      │
  113. │    addition of the lower case letter portion) in 2 lines only:           │
  114. │                                                                          │
  115. │     270  call giveback : WEND                                            │
  116. │          . . .                                                           │
  117. │    1526  (actually, three lines after this line number . . .)            │
  118. │          call giveback : WEND                                            │
  119. │                                                                          │
  120. │    Then compile the modified RBBS-SUB.BAS, and LINK  RBBS-SUB.OBJ        │
  121. │    together with  GIVEBK31.OBJ and the rest of the normal RBBS  OBJect   │
  122. │    files package.                                                        │
  123. └──────────────────────────────────────────────────────────────────────────┘
  124.  
  125.  
  126.  
  127.  
  128. GIVEBACK Version history:
  129.  
  130.  1.0    December 1986 was the first version, for RBBS-PC v14.1D and DoubleDos
  131.         version 4.0
  132.  
  133.  1.2    January 2, 1987  Added a second call to giveback in the WHILE..WEND
  134.         loop which waits for user to enter a command.  DoubleDos only.
  135.  
  136.  1.3    May 20, 1987.  Changed to prevent RBBS modified with GIVEBACK from
  137.         crashing the system when run under naked Dos, that is, without the use
  138.         of DoubleDos.  Replaced direct INT FEh statement, with indirect AH=EEh,
  139.         followed by normal Dos function INT 21h.  DD and Dos obligingly work
  140.         together like this:  DD modifies the INT 21h function tables when it
  141.         starts so as to recognize EEh, and naked Dos ignores functions like EEh
  142.         which are unknown to it.  Possible caution--DD is definitely
  143.         non-standard in making this modification.  This should cause no
  144.         problem, UNLESS you use yet another non-standard program that also
  145.         grabs AH=EEh under INT 21h for another purpose (unlikely).
  146.  
  147. 2.0     Jan 1988.  Version is for DESQview 2.01  (works fine in 2.0 too),
  148.         together with RBBS 15.1c.  It does not supersede GIVEBK13,
  149.         required for operation under DoubleDos.  Although it duplicates some
  150.         lines of code found in RBBSDV.ASM, this is a simple, small, and cleanly
  151.         independent addition.  RBBS, modified to include this revision, will
  152.         work under naked DOS alone, or under DESQview.  (personal note--I run
  153.         only a single node, and prefer to drop all the FILELOCK, RBBSDV, and
  154.         multilink crap and related calls from my personal version of RBBS;
  155.         shrinks the .EXE file and makes it more reliable)
  156.  
  157. 3.0     Feb 1988.  This version consolidates DoubleDos and DESQview routines
  158.         into one that works equally well for RBBS running under either
  159.         multitasker, or under naked DOS.  Calling points are given for both
  160.         RBBS 14.1d and 15.1c.  My hope is that RBBS version 16.0 will
  161.         incorporate this into the release version.
  162.  
  163. 3.1     Apr 1988.  Minor upgrade neatens code and also eliminates the former
  164.         requirement for initializing GIVEBACK by calling GIVEINIT.  It can be
  165.         initialized explicitly as before; but if the user chooses to call
  166.         GIVEBACK straight away, then the initialization will be taken care of
  167.         automatically.
  168.  
  169. (End of comments here-you do not have to remove these comments to assemble.) ~
  170.  
  171.  
  172. GIVESEG SEGMENT 'CODE'
  173.         ASSUME  CS:GIVESEG
  174.         PUBLIC  GIVEINIT        ;the initialization routine, optional
  175.         PUBLIC  GIVEBACK    ;CALL GIVEBACK to give back time slice
  176.  
  177. MultiTasker  DB  -1     ; will indicate which multitasker is running, if any
  178.                         ;-1 means this hasn't yet been called, and
  179.                         ;    initialization is required using GIVEINIT
  180.                         ; 0 means no multitasker is present, only naked dos
  181.                         ; 1 means DESQview is running
  182.                         ; 2 means DoubleDos is running
  183.  
  184. GIVEINIT PROC    FAR
  185.     PUSH    AX    ; save this stuff for safety
  186.         PUSH    BX
  187.         PUSH    CX
  188.         PUSH    DX
  189.         MOV     AX,2B01H                ; DV get version request, result to AX
  190.         MOV     CX,'DE'                 ; Illegal
  191.         MOV     DX,'SQ'                 ;        date, on purpose
  192.         INT     21H                     ; An error indicates DV isn't running
  193.         CMP     AL,0FFH                 ; Are we in DV?
  194.         JE      NO_DV                   ; Jump if not
  195.         MOV     CS:MultiTasker,1      ; 1 will mean DV is present
  196.         JMP     SHORT InitExit
  197. NO_DV:                ; DV isn't here, maybe DD is-let's check
  198.     MOV    AH,0E4h        ; function E4h tests for presence of DoubleDos
  199.     INT    21h          ; does nothing at all if DD not present
  200.     CMP    AL,01          ; 1 indicates DD present, program visible
  201.     JZ    DDhere
  202.     CMP    AL,02         ; 2 indicates DD present, program invisible
  203.     JZ    DDhere
  204.         JMP     NoMultitsk      ; anything else indicates not present, so quit
  205. DDhere: MOV    CS:MultiTasker,2    ;this value indicates DD present
  206.         JMP     SHORT InitExit
  207. NoMultitsk:
  208.         MOV     CS:MultiTasker,0        ;Neither DV nor DD running
  209. InitExit:
  210.         POP     DX                      ;and put it all back
  211.         POP     CX
  212.         POP     BX
  213.     POP    AX
  214.         RET
  215. GIVEINIT ENDP
  216.  
  217.  
  218. API_CALL PROC        ; local DV routine that goes on stack, does whatever
  219.     PUSH    AX    ;  call is passed in BX, then goes off stack
  220.         MOV     AX,101AH
  221.         INT     15H                     ; OSTACK
  222.         MOV     AX,BX
  223.         INT     15H                     ; Parameter
  224.         MOV     AX,1025H
  225.         INT     15H                     ; USTACK
  226.         POP     AX
  227.         RET
  228. API_CALL ENDP
  229.  
  230.  
  231. GIVEBACK PROC FAR       ;Gives up the rest of its time slice when called.
  232.                         ;GIVEINIT will be invoked automatically the first time
  233.                         ; that GIVEBACK is called; GIVEINIT can (optionally)
  234.                         ; be called explicitly to force initialization.
  235.         CMP     CS:MultiTasker,1        ;let's see what's running here
  236.         JZ      DVrunning               ;1 means DESQview is running
  237.         JG      DDrunning               ;2 means DoubleDos is running
  238.         CMP     CS:MultiTasker,0        ;only naked Dos or uninitialized state
  239.                                         ;  remain as possibilities
  240.         JZ      GetOutaHere             ;0 means naked Dos
  241.         CALL    GIVEINIT                ;last remaining possibility is -1
  242.         JMP     GIVEBACK                ;after initializing, try this again
  243.  
  244. GetOutaHere:                            ;nothing else to do, so go back
  245.         RET
  246.  
  247. DVrunning:
  248.         PUSH    BX
  249.         MOV     BX,1000H                ; DV_PAUSE function call
  250.         CALL    API_CALL
  251.         POP     BX
  252.         JMP     SHORT GetOutaHere
  253.  
  254.  
  255. DDrunning:
  256.         push    bp      ;save caller's base pointer register
  257.         mov     bp,sp   ;setup to address off of base pointer register
  258.         push    ax      ;just in case this messes up something
  259.         mov     ax,0EE06h
  260.  
  261. Comment ~       EEh in AH is special DoubleDos giveback interrupt. 06h in AL is
  262. six 55ms giveback intervals = 1/3 sec.  ~
  263.  
  264.         int     21h     ;invokes special DoubleDos giveback interrupt
  265.         pop     ax      ;puts it back
  266.     POP    BP      ;restore callers base pointer register
  267.         JMP     SHORT GetOutaHere
  268.  
  269. GIVEBACK ENDP
  270. GIVESEG  ENDS
  271.          END
  272.